home *** CD-ROM | disk | FTP | other *** search
- //*************** GLOBALS VARS *****************
- // Supporting Fireworks 2.0 10FEB99
-
- //******************* BEHAVIOR FUNCTIONS **********************
-
- //Changes multiple images at once. Accepts a variable number of args in triplets as follows:
- // objStrNS - Javascript object ref for Netscape (ex: document.layers['foo'].document.myImage)
- // objStrIE - JScript object reference for Internet Explorer (ex: document.all['myImage'])
- // imgURL - an image filename, URL encoded. (ex: file.gif, http://www.x.com/y.gif)
- //
- //Tests for browser, and uses the first object string for NS, the second for IE.
- //Sets the image src property to the new filename: document.myImage.src = file.gif.
- //Fails gracefully on older browsers by ensuring the the object exists.
- //If the image is in a layer, fixes the reference so it works. It doesn't hurt
- //to set image.src in a browser (IE3) even if nothing changes.
- //The rest of the code is to support another Action, Swap Image Restore.
- //Builds an array of the original src values and saves it to a global property,
- //in the form of theObj,theObj.src,.... Prevents overwriting these values if called
- //repeatedly, to ensure we use the original src file set in the HTML.
-
- function GrpSwap(grp){
- var i,j=0,newSrc,objName;
- var docGroup = false;
- for (i=1; i < (GrpSwap.arguments.length-1); i+=2) {
- objName = GrpSwap.arguments[i];
- newSrc = GrpSwap.arguments[i+1];
- docGroup = FindGroup(grp, objName);
- if (!docGroup) continue;
- obj = FWFindImage(document,objName,0);
- if (!obj) continue;
- if (obj.isDown) {
- if (obj.downOver) {
- obj.src = obj.downOver;
- }
- } else {
- obj.src = newSrc;
- obj.atRestSrc = obj.initialSrc;
- }
- obj.skipMe = true;
- j++;
- }
- if (!docGroup) return;
- theImages = docGroup.theImages;
- if (theImages) {
- for (i=0; i<theImages.length; i++) {
- var curImg = theImages[i];
- if (curImg.atRestSrc && !curImg.skipMe) {
- curImg.src = curImg.atRestSrc;
- }
- curImg.skipMe = false;
- }
- }
- }
-
- function GrpRestore(grp){
- var docGroup = eval("document.FWG_"+grp);if (!docGroup) return;
- theImages = docGroup.theImages;
- if (theImages) {
- for (i=0; i<theImages.length; i++) {
- var curImg = theImages[i];
- if (curImg.atRestSrc) {
- curImg.src = curImg.atRestSrc;
- }
- }
- }
- }
-
- function FWFindImage(doc, name, j)
- {
- var theImage=false;
- if (doc.images) {
- theImage = doc.images[name];
- }
- if (theImage) return theImage;
- if (doc.layers) {
- for (j=0; j<doc.layers.length; j++) {
- theImage = FWFindImage(doc.layers[j].document, name, 0);
- if (theImage) return(theImage);
- }
- }
- return(false);
- }
-
- function FindGroup(grp, imageName) {
- var img = FWFindImage(document, imageName, 0);
- if (!img) return(false);
- var docGroup = eval("document.FWG_"+grp);
- if (!docGroup) {
- docGroup = new Object;
- eval("document.FWG_"+grp+" = docGroup");
- docGroup.theImages = new Array;
- }
- if (img) {
- var i;
- for (i=0; i<docGroup.theImages.length; i++) {
- if (docGroup.theImages[i] == img) break;
- }
- docGroup.theImages[i] = img;
- if (!img.atRestSrc) {
- img.atRestSrc = img.src;
- img.initialSrc = img.src;
- }
- }
- return(docGroup);
- }
-
- //Preloads multiple images files in order. Accepts a variable number of args
- //(each should be quoted):
- // imgURL - an image filename, URL encoded. (ex: file.gif, http://www.x.com/y.gif)
- //
- //Creates a new array of Image objects. With each one, it assigns an image source
- //from the argument list. These are downloaded essentially simultaneously into the
- //client cache. When the user needs a new image file (for example: they go to the
- //next web page), the browser should quickly find this image in the cache.
- //!!! IMPORTANT !!! This function is also defined in file "Preload Images.htm".
- //Any edits must be made there as well as here.
-
- function MM_preloadImages() { //v2.0
- if (document.images) {
- var imgFiles = MM_preloadImages.arguments;
- if (document.preloadArray==null) document.preloadArray = new Array();
- var i = document.preloadArray.length;
- with (document) for (var j=0; j<imgFiles.length; j++) if (imgFiles[j].charAt(0)!="#"){
- preloadArray[i] = new Image;
- preloadArray[i++].src = imgFiles[j];
- } }
- }
-
-
- //******************* API **********************
-
-
- //Checks for the existence of images.
- //If none exist, returns false so this Action is grayed out.
-
- function canAcceptBehavior(){
- var retVal = "";
- var imgs = getAllObjectRefs("IE 4.0","IMG");
- if (imgs.length > 0) {
- retVal = "onMouseOver";
- }
- if (retVal)
- return retVal;
- return false;
- }
-
-
-
- //Returns Javascript functions to be inserted in HTML head with script tags.
-
- function behaviorFunction(){
- return "MM_preloadImages,FindGroup,FWFindImage,GrpRestore,GrpSwap"
- }
-
-
- //Returns fn call to insert in HTML tag <TAG... onEvent='thisFn(arg)'>
- //Gets list of imgSrcs from doc attribute. With each imgSrc, it gets the parallel
- //img name from select 'menu'. Each imgSrc & imgObj are embedded as args.
- function applyBehavior() {
- /*
- return "GrpSwap('Joe','Foo','foo.img')"
- }
- function yo() {
- */
- var retVal="",i,j,argList="",fnArray,imgSrcArray,imgSrc,imgObj,imgObjIE,newName;
- var imgObjsArray=document.MM_imgObjsArray;
- var imgList="";
-
- grpName = document.theForm.grpName.value;
- imgSrcArray = document.MM_myImgSrcs; //get global list of imgSrcs
- for (i=0; i<imgSrcArray.length; i++) { //with each imgSrc
- imgSrc = imgSrcArray[i];
- if (imgSrc) { //if not empty
- if (argList) argList += ","; //if stuff already in list, add comma
- theName = imgObjsArray[i].getAttribute("name");
- if (!theName){ //if the image is unnamed
- //from this array, get unique image name
- newName = getUniqueName("IMG","Image",imgObjsArray);
- imgObjsArray[i].setAttribute("name",newName); //rename image in document
- theName = imgObjsArray[i].getAttribute("name");
- }
- argList += "'"+escape(theName)+"','"+escape(imgSrc)+"'";
- imgList += (imgList?",":"")+"'"+escape(imgSrc)+"'";
- break;
- }
- }
- if (!argList) retVal = MSG_NoImgsSelected;
- else { //OK
- //Add or remove MM_swapImgRestore() based on checkbox setting
- selObj = dreamweaver.getBehaviorElement();
- if (!selObj){
- selArr = dreamweaver.getSelection();
- selObj = dreamweaver.offsetsToNode(selArr[0],selArr[1]);
-
- }
-
- //Add or remove MM_preloadImages() based on checkbox setting
- var obj = dreamweaver.getDocumentDOM("document").body;
- if (document.theForm.preload.checked) { //add preload call to onLoad handler
- argList += ",\'"+document.preloadId+"\'"; //add uniqueName to main fn call
- setHandler(obj,"onLoad","MM_preloadImages("+imgList+",'"+document.preloadId+"')",document.preloadId);
- } else {
- delHandler(obj,"onLoad","MM_preloadImages",document.preloadId);
- }
-
- if (document.theForm.restore) {
- var theRestore = "GrpRestore('" + grpName + "')";
- if (document.theForm.restore.checked) { //add restore to onMouseOut handler
- setHandler(selObj,'onMouseOut',theRestore);
- } else { //remove it
- delHandler(selObj,'onMouseOut', 'GrpRestore', grpName);
- }
- }
-
- retVal = "GrpSwap('"+grpName+"'," + argList+")"; //create correct function call
- }
- return retVal
- }
-
-
- //Given the original function call, this parses out the args and updates
- //the UI. Loops through each imgObj,imgSrc pair.
- //If imgObj already present in menu, stuff imgSrc in imgSrcArray. If imgObj
- //doesn't exist, add to menu, and extend imgSrcArray.
-
- function inspectBehavior(behFnCallStr){
- var argArray,imgSrcArray,found,numImgs,i,imgObj,imgSrc,j,imgObjNum;
- var imgsArray = document.MM_imgObjsArray = createObjsArray("IMG");
-
- argArray = extractArgs(behFnCallStr);//get new list of imgObj,imgSrc pairs
- imgSrcArray = document.MM_myImgSrcs; //get the prior list of imgSrcs
- group=unescQuotes(argArray[1]);
- numImgs = document.MM_imgObjsArray.length;
- for (i=2; i<(argArray.length-1); i+=2){ //with each imgObj,imgSrc pair
- imgName=unescQuotes(argArray[i]);
- imgSrc=unescape(argArray[i+1]);
- found = false;
- for (j=0; j<numImgs; j++){ //check if imgObj is in ref list
- theName = document.MM_imgObjsArray[j].getAttribute("name");
- if (theName == imgName) { //if imgObj there
- imgSrcArray[j] = imgSrc; //store imgSrc at that pos
- if (imgSrc) addStarToMenuItem(document.theForm.menu,j);//if non-empty, mark with *
- found = true;
- break;
- }
- }
- if (!found) alert(errMsg(MSG_ImgNotFound,imgName,imgSrc)); //if image name not found
- }
- document.theForm.grpName.value = group;
- document.MM_myImgSrcs = imgSrcArray; //save updated imageSrc list
- displayImgSrc(); //load the imageSrc for selected image
-
- //Determine if preloading, get id
- if (i < argArray.length) document.preloadId = argArray[i]; //unique id exists, get it
- document.theForm.preload.checked = (argArray.length > i); //if preload, check box
-
- //If restore checkbox is available, see if MM_swapImgRestore() exists, and check the box
- var theObj = findObject("restoreOption");
- if (theObj) { //restore checkbox is a possibility
- var selObj=dreamweaver.getBehaviorElement();
- if (selObj && selObj.tagName != "A") selObj = selObj.parentNode; //move out to A tag if needed
- if (selObj && selObj.tagName == "A") if (document.theForm.restore) {
- document.theForm.restore.checked = getHandler(selObj,'onMouseOut','GrpRestore', group);
- }
- }
-
- }
-
-
- //Given the original function call, this parses out the args and updates
- //the code. If there's a preload id at the end of the arglist, deletes
- //the preload handler. If there's a swap restore call, deletes that.
-
- function deleteBehavior(behFnCallStr){
- var argArray,obj,selArr,selObj;
-
- argArray = extractArgs(behFnCallStr);//get new list of imgObj,imgSrc pairs
- group=unescQuotes(argArray[1]);
-
- //Maybe remove preload handler
- if ((argArray.length-2)%2 == 1) { //if extra arg
- document.preloadId = argArray[argArray.length-1]; //unique id exists, get it
- obj = dreamweaver.getDocumentDOM("document").body;
- if (obj.innerHTML.indexOf(document.preloadId) == -1) // if swap image not just moved
- delHandler(obj,"onLoad","MM_preloadImages",document.preloadId);
- }
-
- //Maybe remove swap restore handler
- selObj=dreamweaver.getBehaviorElement();
- /* selObj appears to always be null, so we never delete the
- GrpRestore. Oh well... jba */
- if (selObj && selObj.tagName != "A") selObj = selObj.parentNode; //move out to A tag if needed
- alert(selObj);
- if (selObj && selObj.tagName == "A") {
- delHandler(selObj,'onMouseOut','GrpRestore', group);
- }
-
- }
-
-
-
-
- //***************** LOCAL FUNCTIONS ******************
-
- //Load the select menu with image names.
- //Also sets the global property MM_myImgSrcs to the right num of items.
-
- function initializeUI(){
- var niceNameSrcArray, nameArray, i, selTag="";
- var imgSrcArray = new Array();
-
- //Determine if RESTORE is an option. If not, remove UI for it
- //the dreamweaver.getBehaviorTag() check ensures the checkbox
- //is not available if a behavior is attached to a timeline
- var removeCheckbox = false;
- if (!dreamweaver.getBehaviorTag() ) //if behavior is in a timeline
- removeCheckbox = true;
- else{
- if (dreamweaver.getBehaviorElement()) selTag = dreamweaver.getBehaviorElement().tagName;
- if (!selTag) selTag = getSelectionTag();
- if (selTag!="A" && selTag!="IMG") //if sel not A or IMG
- removeCheckbox = true;
- }
- if (removeCheckbox){
- var theObj = findObject("restoreOption");
- if (theObj) theObj.outerHTML = ""; //remove restoreOption checkbox
- }
-
-
- //Create unique ID in case of preload
- document.preloadId = "#"+((new Date()).getTime());
-
- //Build and load picklist of images
- niceNameSrcArray = getAllObjectRefs("IE 4.0","IMG");
- nameArray = niceNames(niceNameSrcArray,TYPE_Image);
- for (i=0; i<nameArray.length; i++){
- document.theForm.menu.options[i]=new Option(nameArray[i]); //load menu
- imgSrcArray[i] = "";
- }
- pickSelectedImage(); //if an image is selected, selects it in the picklist
- document.MM_myImgSrcs = imgSrcArray; //set global
-
- document.theForm.imgSrc.focus(); //set focus on textbox
- document.theForm.imgSrc.select(); //set insertion point into textbox
- }
-
-
-
- //Given imageSrc in form, looks up the menu's selection number, and stores the
- //new imageSrc at that position in the global document property "MM_myImgSrcs".
-
- function storeImgSrc(){
- var newImgSrc, imgSrcArray, menuIndex, newMenuText;
-
- newImgSrc = document.theForm.imgSrc.value;
- imgSrcArray = document.MM_myImgSrcs; //get the prior list of imgSrcs
- menuIndex = document.theForm.menu.selectedIndex; //get index to swap
- imgSrcArray[menuIndex] = newImgSrc; //swap
- document.MM_myImgSrcs = imgSrcArray; //rewrite list
- if (newImgSrc) { //if non-empty, mark with *
- addStarToMenuItem(document.theForm.menu, menuIndex);
- } else { //nothing to store, strip off any previous star
- newMenuText = stripStar(document.theForm.menu.options[menuIndex].text); //remove if old star
- document.theForm.menu.options[menuIndex]=new Option(newMenuText); //add new line to menu
- }
- document.theForm.menu.selectedIndex = menuIndex; //reset selection index
- }
-
-
- //Looks at the menu of names, and returns the imgSrc associated with the
- //selected item. Example: if the 2nd menu item's selected, returns 2nd item
- //stored in property "MM_myImgSrcs".
-
- function displayImgSrc(){
- var imgSrcArray, curImageSrcNum, imgSrc;
-
- imgSrcArray = document.MM_myImgSrcs; //get the list of imgSrcs
- curImageSrcNum = document.theForm.menu.selectedIndex; //get index selected
- imgSrc = imgSrcArray[curImageSrcNum]; //lookup imgSrc
- document.theForm.imgSrc.value= imgSrc; //write into text field
- }
-
-
-
- //Invokes dialog to allow user to select filename. Puts value in text input.
-
- function browseFileAndStore(){
- var fileName;
- fileName = browseForFileURL("select", "", true); //returns a local filename
- if (fileName) {
- document.theForm.imgSrc.value = fileName;
- storeImgSrc();
- }
- }
-
-
- function pickSelectedImage(){
- var imgsArray = document.MM_imgObjsArray = createObjsArray("IMG");
- var arrLen = imgsArray.length;
- var selArr = dreamweaver.getSelection();
- var selObj = dreamweaver.offsetsToNode(selArr[0],selArr[1]);
-
- for (i=0;i<arrLen;i++){
- if (imgsArray[i]==selObj)
- document.theForm.menu.selectedIndex=i;
- }
- }
-
- function identifyBehaviorArguments(fnCallStr) {
- var argList, argArray, numArgGroups, i;
-
- argList = "ign"; /* ignore the group name */
- argArray = extractArgs(fnCallStr);
- numArgGroups = (argArray.length - 2) / 2; //args come in pairs
- for (i=0; i<numArgGroups; i++) { //with each NSobj,IEobj,URL triplet
- argList += ((argList)?",":"")+"ignore,DEP";
- }
- return argList;
- }
-
- //Creates a unique name for objs of tagName, using tagString
- //for instance: if tagString = Image, returns a name like Image1
- function getUniqueName(tagName,tagString,tagNameObjsArray){
- var frameListSize,objName,dupe=true,counter=1;
- var objsArray=arguments[2],objsArrayLen = objsArray.length;
-
- while (dupe==true){ //check new name against name of all other tagName objs
- dupe=false;
- objName = tagString + counter++;
- //iterates through possible names: tagName1, then tagName2, etc.
- for (i=0;dupe==false && i<objsArrayLen;i++){
- //if another object of this type has the same name
- if (objsArray[i].getAttribute("name") == objName)
- dupe=true; //then repeat the loop, trying a new name
- }
- }
- return objName; //return new name
-
- }
-
- //Returns an array of objects of tagName
- //If doc is in a frameset, searches all frames in parent
- function createObjsArray(tagName){
- var frameListLen,objsArray=new Array(),thisFrame;
- if (dreamweaver.getDocumentDOM('parent')){//if frames
- frameListLen = dreamweaver.getDocumentDOM('parent').getElementsByTagName('frame').length;
- for (i=0;i<frameListLen;i++){
- thisFrame = 'parent.frames[' + i + ']';
- objsArray = objsArray.concat(dreamweaver.getDocumentDOM(thisFrame).getElementsByTagName(tagName));
- }
- } else //if no frames
- objsArray = dreamweaver.getDocumentDOM("document").getElementsByTagName(tagName);
- return objsArray;
- }
-
- //*************** GENERIC DOM MANIPULATION FNS *****************
-
- //Returns a function call if exists in event handler.
- // obj - DOM object, such as dreamweaver.getDocumentDOM().body
- // eventName - "onLoad", "onClick" etc (not case sensitive)
- // fnName - "MM_preloadImages" etc.
- // optStr - (optional) function call must contain this string to be found
- //Given <TAG onEvent="aaa();bbb();ccc()">,
- //calling getHandler(tagObj,'onEvent','bbb') will
- //return "bbb()". Returns empty if event or fn don't exist.
-
- function getHandler(obj,eventName,fnName, optStr) {
- var eventStr,fnArray,i,theChunk,retVal = "";
- eventStr = obj.getAttribute(eventName);
- if (eventStr) { //find previous call, or add it
- fnArray = dreamweaver.getTokens(eventStr,";");
- for (i=0; i<fnArray.length; i++) { //look at each code chunk
- if (fnArray[i].indexOf(fnName+'(') != -1 && (!optStr || //fn call found
- fnArray[i].indexOf(optStr) != -1)) {
- retVal = fnArray[i]; break;
- } }
- }
- return retVal
- }
-
-
-
- //Replaces or adds a fn call to an event handler
- // obj - DOM object, such as dreamweaver.getDocumentDOM().body
- // eventName - "onLoad", "onClick" etc (not case sensitive)
- // fnCall - "myFun('arg1','arg2')" etc.
- // optStr - (optional) function call must contain this string to be found
- //Given <TAG onEvent="aaa();bbb();ccc()">,
- //calling setHandler(tagObj,'onEvent','bbb(1,2)') will
- //replace "bbb()" with the altered fn call. If the event
- //does not exist, adds it. It fn didn't exist, adds it to the
- //end of the list.
-
- function setHandler(obj,eventName,fnCall, optStr) {
- var eventStr,fnName,fnArray=new Array(),i=0;
- eventStr = obj.getAttribute(eventName);
- if (eventStr) { //if event exists
- fnName = fnCall.substring(0,fnCall.indexOf("("));
- fnArray = dreamweaver.getTokens(eventStr,";");
- for (i; i<fnArray.length; i++) //search for fnName
- if (fnArray[i].indexOf(fnName+'(') != -1 && (!optStr || //fn call found
- fnArray[i].indexOf(optStr) != -1)) break;
- }
- fnArray[i] = fnCall;
- obj.setAttribute(eventName,fnArray.join(";"));
- return true
- }
-
-
-
- //Deletes a fn call from an event handler
- // obj - DOM object, such as dreamweaver.getDocumentDOM().body
- // eventName - "onLoad", "onClick" etc (not case sensitive)
- // fnName - "MM_preloadImages" etc.
- // optStr - (optional) function call must contain this string to be found
- //Given <TAG onEvent="aaa();bbb();ccc()">,
- //calling delHandler(tagObj,'onEvent','bbb') will
- //remove "bbb();". If it is the last fn in the handler,
- //removes the event entirely.
-
- function delHandler(obj,eventName,fnName, optStr) {
- var eventStr,fnArray=new Array(),i=0,j;
- eventStr = obj.getAttribute(eventName);
- if (eventStr) { //if event exists
- fnArray = dreamweaver.getTokens(eventStr,";");
- for (i; i<fnArray.length; i++) { //look at each code chunk
- if (fnArray[i].indexOf(fnName+'(') != -1 && (!optStr || //fn call found
- fnArray[i].indexOf(optStr) != -1)) { //and, if given, optStr exists
- if (fnArray.length == 1) { //if last one, remove attribute
- obj.removeAttribute(eventName);
- } else { //pull out
- for (j=i; j<fnArray.length; j++) fnArray[j] = fnArray[j+1]; //shift array
- fnArray.length--;
- obj.setAttribute(eventName,fnArray.join(';'));
- }
- break;
- } }
- }
- return true
- }
-
-
-
- //Returns the tag for the current selection, such as
- //IMG, A, DIV etc. Always uppercase.
-
- function getSelectionTag() {
- var retVal = "";
- var selArr = dreamweaver.getSelection()
- var selObj=dreamweaver.offsetsToNode(selArr[0],selArr[1]);
- if (selObj && selObj.tagName) retVal = selObj.tagName;
- return retVal
- }
-
- //**************** GENERIC FUNCTIONS ****************
-
- //function extractArgs(behFnCallStr){
- //function stripStar(theStr) {
- //function addStarToMenuItem(theSelect,menuIndex) {
- //function escQuotes(theStr){
- //function unescQuotes(theStr){
- //function niceNames(objRefArray,objTypeStr) {
- //function nameReduce (objName) {
- //function errMsg() {
- //function findObject(objName, parentObj) {
-
-
-
- //**************** GENERIC FUNCTIONS ****************
-
- //function extractArgs(behFnCallStr){
- //function stripStar(theStr) {
- //function addStarToMenuItem(theSelect,menuIndex) {
- //function escQuotes(theStr){
- //function unescQuotes(theStr){
- //function niceNames(objRefArray,objTypeStr) {
- //function nameReduce (objName) {
- //function errMsg() {
- //function findObject(objName, parentObj) {
-